package com.pansoft.newasset.fragment;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.google.android.material.appbar.AppBarLayout;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.core.xml.StubObject;
import com.efounder.chat.activity.ChatLocalSearchActivity;
import com.efounder.chat.db.WeChatDBManager;
import com.efounder.chat.event.SystemInitOverEvent;
import com.efounder.chat.model.UpdateBadgeViewEvent;
import com.efounder.chat.utils.LXGlideImageLoader;
import com.efounder.chat.view.CommonOtherPopWindow;
import com.efounder.chat.zxing.qrcode.MipcaActivityCapture;
import com.efounder.constant.EnvironmentVariable;
import com.efounder.frame.baseui.BaseFragment;
import com.efounder.interfaces.BadgeUtil;
import com.efounder.mobilecomps.contacts.ClearEditText;
import com.efounder.mobilecomps.contacts.User;
import com.efounder.model.RefreshViewEvent;
import com.efounder.service.Registry;
import com.efounder.util.AbFragmentManager;
import com.efounder.util.EnvSupportManager;
import com.efounder.utils.JfResourceUtil;
import com.efounder.utils.ResStringUtil;
import com.gyf.immersionbar.ImmersionBar;
import com.pansoft.newasset.adapter.NewAssetMain2Adapter;
import com.pansoft.newasset.adapter.NewAssetMenuAdapter;
import com.pansoft.newasset.bean.MenuBean;
import com.pansoft.nfc.mifare.Common;
import com.pansoft.nfc.mifare.activity.MifareAddCardActivity;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.activity.AssetAllApplicationActivity;
import com.pansoft.openplanet.activity.AssetEditApplicationActivity;
import com.pansoft.openplanet.activity.BCChatListActivity;
import com.pansoft.openplanet.activity.BleBlutoothScanActivity;
import com.pansoft.openplanet.activity.EnergyQRCodeActivity;
import com.pansoft.openplanet.activity.LuckMoneyPrepareActivity;
import com.pansoft.openplanet.activity.SafetyArchitectureActivity;
import com.pansoft.openplanet.activity.StackActivity;
import com.pansoft.openplanet.activity.TabBottomActivityForTalkChain;
import com.pansoft.openplanet.activity.TradeLineActivity;
import com.pansoft.openplanet.activity.TransferActivity;
import com.pansoft.openplanet.bean.Account;
import com.pansoft.openplanet.bean.EventMenuBean;
import com.pansoft.openplanet.bean.WalletBean;
import com.pansoft.openplanet.constant.IPAssetsConstant;
import com.pansoft.openplanet.db.AccountDao;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.utilcode.util.SPUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import q.rorbin.badgeview.QBadgeView;

import static com.efounder.frame.utils.Constants.CHAT_USER_ID;

/**
 * 新版首页
 *
 * @author will
 */
public class NewAssetMain2Fragment extends BaseFragment implements View.OnClickListener {

    NestedScrollView nestedScrollView;
    private Toolbar toolbar;
    private GridView menuGrid;
    private NewAssetMenuAdapter menuAdapter;
    private List<MenuBean> menuBeans = new ArrayList<>();
    private List<StubObject> mainMenus;
    private List<WalletBean> walleatBeanList = new ArrayList<>();
    private AccountDao accountDao;
    private String filePath = "";
    private String address = "";
    private User user;
    private ImageView ivAvatar;
    private SmartRefreshLayout smartRefreshLayout;
    private ImageView ivBarAdd1;
    private RecyclerView recyclerView;
    private NewAssetMain2Adapter recycleViewAdapter;
    private int mMaskColor;
    private AppBarLayout appBarLayout;
    private FrameLayout clSmallMenu;
    private FrameLayout clSearchbar;
    private View viewMenuBg;
    private View viewTopSmallBg;

    private View viewTopSearchBg;

    private QBadgeView badgeView, badgeView2;
    private ImageView ivMsg;
    private ImageView ivMsg1;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.new_asset_activit_main2, container, false);
        if(!EventBus.getDefault().isRegistered(this)){
            EventBus.getDefault().register(this);
        }
        //背景颜色
        mMaskColor = JfResourceUtil.getSkinColor(R.color.title_Background);
        getWallet();
        initView(view);

        getMenuList();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshUserInfo();
        ((NewAssetCardsFragment) getChildFragmentManager().findFragmentById(R.id.fragment_cards)).refresh();
    }

    private void initView(final View view) {
        ivAvatar = view.findViewById(R.id.iv_bar_avatar);
        ivAvatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((TabBottomActivityForTalkChain) getActivity()).getDrawerLayout().openDrawer(Gravity.LEFT);
            }
        });
        toolbar = view.findViewById(R.id.toolbar);
        nestedScrollView = view.findViewById(R.id.alipay_rv);
        viewMenuBg = (View) view.findViewById(R.id.view_menu_bg);
        viewTopSearchBg = (View) view.findViewById(R.id.view_top_search_bg);
        viewTopSmallBg = (View) view.findViewById(R.id.view_top_small_bg);
        menuGrid = view.findViewById(R.id.grid_menu);
        smartRefreshLayout = view.findViewById(R.id.refreshLayout);
        menuAdapter = new NewAssetMenuAdapter(getActivity(), menuBeans);
        menuGrid.setAdapter(menuAdapter);
        menuGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                handleIntent(menuBeans.get(position));
            }
        });
        smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
//                recycleViewAdapter.refreshData();
                ((NewAssetTotalFragment) getChildFragmentManager().findFragmentById(R.id.fragment_asset)).refreshData();
                smartRefreshLayout.finishRefresh(1200);
            }
        });
        appBarLayout = (AppBarLayout) view.findViewById(R.id.abl_bar);
        clSmallMenu = view.findViewById(R.id.cl_small_menu);
        clSearchbar = view.findViewById(R.id.cl_searchbar);
        initClickIcon(view);
        initHeaderView();
        if (EnvSupportManager.isAssetHasMsg()) {
            BadgeUtil.initBadge();
            initBadge();
        }

        //沉浸式状态栏
        if(immersionBarEnabled()){
            ImmersionBar.with(this).init();
            ImmersionBar.setTitleBar(this,toolbar);
        }
    }

    /**
     * 消息图标的角标
     */
    private void initBadge() {
        if (badgeView == null) {
            badgeView = new QBadgeView(getActivity());
            badgeView.setBadgePadding(3, true);
            badgeView.setBadgeGravity(Gravity.END | Gravity.TOP);
            badgeView.bindTarget(ivMsg);
        }
        //MuleDelivery的“我的”界面md_wd
        int unReadCount = BadgeUtil.getCount("wode");
        badgeView.setBadgeNumber(unReadCount);

        if (badgeView2 == null) {
            badgeView2 = new QBadgeView(getActivity());
            badgeView2.setBadgePadding(3, true);
            badgeView2.setBadgeGravity(Gravity.END | Gravity.TOP);
            badgeView2.bindTarget(ivMsg1);
        }
        badgeView2.setBadgeNumber(unReadCount);
    }

    private void handleIntent(MenuBean menuBean) {
        String androidShow = menuBean.getClassName();
        try {
            //交易
            if ("tx".equals(androidShow)) {
                TradeLineActivity.startTradeLineActivity
                        (getActivity(), IPAssetsConstant.CHAIN_ID_TURBOCHAIN, ResStringUtil.getString(R.string.open_planet_transfer_list), walleatBeanList.get(0).getAddress(),
                                "", walleatBeanList.get(0).getBalance(), null,
                                walleatBeanList.get(0).getFilePath(), 0);
                //未开通
            } else if ("todo".equals(androidShow)) {
                new AlertDialog.Builder(getActivity()).setTitle(ResStringUtil.getString(R.string.open_planet_asset_mine_pwr_one_click_coin))
                        .setMessage(ResStringUtil.getString(R.string.open_planet_recharge_no_dredge))
                        .setCancelable(true)
                        .setPositiveButton(R.string.common_text_confirm, null).show();
                //安全加固
            } else if ("safe".equals(androidShow)) {
                Intent intent = new Intent(getActivity(), SafetyArchitectureActivity.class);
                intent.putExtra("filePath", filePath);
                startActivity(intent);
                //红包
            } else if ("com.pansoft.openplanet.activity.LuckMoneyPrepareActivity".equals(androidShow)) {
                LuckMoneyPrepareActivity.start(getActivity());
                //没配置页面
            } else if (TextUtils.isEmpty(androidShow)) {
                if(menuBean.getIcon().equals("new_asset_icon_more")){
                    //更多界面
                    AssetAllApplicationActivity.start(getActivity());
                }

                return;
                //其他
            } else {
                AbFragmentManager abFragmentManager = new AbFragmentManager(getActivity());
                abFragmentManager.startActivity(menuBean.getStubObject(), 0, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //throw  new RuntimeException("ceshi");
    }

    private void refreshUserInfo() {
        try {
            user = WeChatDBManager.getInstance().getOneUserById(Integer.valueOf(EnvironmentVariable.getProperty(CHAT_USER_ID)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        LXGlideImageLoader.getInstance().showUserAvatar(getActivity(), ivAvatar, user.getAvatar());
    }

    private void initHeaderView() {

        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                int absVerticalOffset = Math.abs(verticalOffset);//AppBarLayout竖直方向偏移距离px
                int totalScrollRange = appBarLayout.getTotalScrollRange();//AppBarLayout总的距离px
                //Log.i(TAG, "totalScrollRange:" + totalScrollRange);

                int alpha = absVerticalOffset >= 255 ? 255 : absVerticalOffset;
                int alphaDouble = absVerticalOffset * 2 >= 255 ? 255 : absVerticalOffset * 2;

                //背景颜色转化成RGB的渐变色
                int argb = Color.argb(alpha, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor));
                int argbDouble = Color.argb(alphaDouble, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor));
                //appBarLayout上滑一半距离后小图标应该由渐变到全透明
                int title_small_offset = (500 - absVerticalOffset) < 0 ? 0 : 500 - absVerticalOffset;

//                LogUtils.i(absVerticalOffset, alpha, alphaDouble, title_small_offset);

                int title_small_argb = Color.argb(title_small_offset, Color.red(mMaskColor),
                        Color.green(mMaskColor), Color.blue(mMaskColor));
                //appBarLayout上滑不到一半距离
                if (absVerticalOffset <= 255) {
                    //上方的搜索区
                    clSearchbar.setVisibility(View.VISIBLE);
                    //上方四个按钮
                    clSmallMenu.setVisibility(View.GONE);
                    //为了和下面的大图标渐变区分,乘以2倍渐变
                    viewTopSearchBg.setBackgroundColor(argb);

                    // viewTopSearchBg.setBackgroundColor(getResources().getColor(R.color.title_Background));
                } else {
                    clSearchbar.setVisibility(View.GONE);
                    clSmallMenu.setVisibility(View.VISIBLE);
                    //appBarLayout上滑一半距离后小图标应该由渐变到全透明
                    viewTopSmallBg.setBackgroundColor(title_small_argb);
                    // viewTopSmallBg.setBackgroundColor(getResources().getColor(R.color.title_Background));

                }
                //上滑时遮罩由全透明到半透明
                viewMenuBg.setBackgroundColor(argbDouble);
                // viewMenuBg.setBackgroundColor(getResources().getColor(R.color.title_Background));

            }
        });
    }


    /**
     * 读取菜单配置
     */
    private void getMenuList() {
        menuBeans.clear();
        mainMenus = Registry.getRegEntryList("NewAssetRoot");
        //1、获取缓存的菜单数据
        boolean isCache = !SPUtils.getInstance(AssetEditApplicationActivity.ASSET_MENU).getString("NewAssetRoot", "").equals("");
        //2.如果有缓存从缓存中读取，否则从配置菜单中读取
        if (isCache) {
            //2.1 读取缓存数据
            String cacheMenu = SPUtils.getInstance(AssetEditApplicationActivity.ASSET_MENU).getString("NewAssetRoot", "");
            //2.2解析缓存菜单集合
            List<MenuBean> cacheMenuBeans = JSONArray.parseArray(cacheMenu, MenuBean.class);
            //2.3 循环判断当前缓存中的菜单是否在配置文件中存在   防止配置文件中删除功能后缓存中依然有菜单功能的存在
            for(MenuBean menuBean : cacheMenuBeans){
                //2.3.1获取缓存菜单的名称 (通过多语言的key)
                String menuName = menuBean.getMultiLanguageKey();
                if(mainMenus == null){
                    return;
                }
                //判断缓存中的菜单是否在配置文件中存在
                boolean isExist = false;
                //2.3.2 循环 配置文件菜单集合
                for(StubObject stubObject : mainMenus){
                    //2.3.3 如果配置文件中有缓存的功能
                    if(menuName.equals(stubObject.getString("multiLanguageKey",""))){
                        //2.3.4 如果存在设置为true
                        isExist = true;
                        //2.3.5  重新设置名称  防止切换语言多语言
                        menuBean.setName(stubObject.getCaption());
                    }
                }
                //2.3.5 如果不存在将缓存菜单中的数据移除
                if(!isExist){
                    //移除
                    cacheMenuBeans.remove(menuBean);
                }
                //重新保存缓存数据  重新加载了多语言的菜单名称
                SPUtils.getInstance(AssetEditApplicationActivity.ASSET_MENU).put("NewAssetRoot",JSONArray.toJSONString(cacheMenuBeans));
            }

            //2.3 加载数据到顶部列表中
            menuBeans.addAll(cacheMenuBeans);
            //添加更多按钮
            if(mainMenus!=null){
                StubObject stubObject = mainMenus.get(mainMenus.size()-1);
                menuBeans.add(new MenuBean(stubObject.getString("icon", ""),
                stubObject.getCaption(),
                stubObject.getString("AndroidShow", ""),true));
            }
        } else {
            if (mainMenus != null) {
                for (int i = 0; i < mainMenus.size(); i++) {
                    StubObject stubObject = mainMenus.get(i);
                    MenuBean menuBean = new MenuBean(stubObject.getString("icon", ""),
                            stubObject.getCaption(),
                            stubObject.getString("AndroidShow", ""),stubObject.getString("multiLanguageKey",""));
                    menuBean.setStubObject(stubObject);
                    menuBeans.add(menuBean);
                }
            }
        }
        menuAdapter.notifyDataSetChanged();
    }

    /**
     * 获取本地钱包地址
     */
    private List<WalletBean> getWallet() {

        Account mainAccount = new AccountDao(getActivity()).getMainAccount();
        if (mainAccount == null) {
            mainAccount = accountDao.getAccount(EnvironmentVariable.getProperty("tc_ethAddress"));
            if (mainAccount != null) {
                mainAccount.setMaster(true);
                mainAccount.setEnable(true);
                mainAccount.setImUserId(EnvironmentVariable.getProperty(CHAT_USER_ID));
                accountDao.insertOrReplace(mainAccount);
            } else {
                return walleatBeanList;
            }
        }

        WalletBean walletBean = new WalletBean();
        walletBean.setAddress(mainAccount.getAddress());
        walletBean.setFile(new File(mainAccount.getFileName()));
        walletBean.setFilePath(mainAccount.getFileName());
        walletBean.setAccountName(mainAccount.getAcccountName());
        walletBean.setAvatar(mainAccount.getAccountAvatar());
        walleatBeanList.add(walletBean);
        address = walleatBeanList.get(0).getAddress();
        filePath = walleatBeanList.get(0).getFilePath();
        return walleatBeanList;
    }

    private void showPopWindow(ImageView ivMore) {
        final CommonOtherPopWindow commonOtherPopWindow = new CommonOtherPopWindow(getActivity());
        commonOtherPopWindow.addMenuButton(ResStringUtil.getString(R.string.chat_saoyisao), R.drawable.new_asset_more_scan)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        try {
                            Intent intent = new Intent(getActivity(), MipcaActivityCapture.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            getActivity().startActivity(intent);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        commonOtherPopWindow.dismiss();
                    }
                });
        commonOtherPopWindow.addMenuButton(ResStringUtil.getString(R.string.new_asset_add_card), R.drawable.new_asset_more_add_card)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        addCard();
                        commonOtherPopWindow.dismiss();
                    }
                });
        commonOtherPopWindow.addMenuButton(ResStringUtil.getString(R.string.new_asset_add_device), R.drawable.new_asset_more_add_device)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        commonOtherPopWindow.dismiss();
                    }
                });
        commonOtherPopWindow.showPopupWindow(ivMore);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        //扫一扫
        if (id == R.id.ll_scan || id == R.id.iv_scan || id == R.id.iv_bar_scan || id == R.id.tv_scan) {
            Intent intent = new Intent(getActivity(), MipcaActivityCapture.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            getActivity().startActivity(intent);
            //PWR转账
        } else if (id == R.id.ll_pay || id == R.id.iv_pay || id == R.id.iv_bar_pay || id == R.id.tv_pay) {
            Intent intent = new Intent(getActivity(), TransferActivity.class);
            intent.putExtra("myaddress", walleatBeanList.get(0).getAddress());
            intent.putExtra("balance", walleatBeanList.get(0).getBalance());
            intent.putExtra("filePath", walleatBeanList.get(0).getFilePath());
            startActivity(intent);
            //PWR收款
        } else if (id == R.id.ll_receive || id == R.id.iv_receive || id == R.id.iv_bar_receive || id == R.id.tv_receive) {
            Intent intent = new Intent(getActivity(), EnergyQRCodeActivity.class);
            startActivity(intent);
            //积分卡
        } else if (id == R.id.ll_cards || id == R.id.iv_cards || id == R.id.iv_bar_cards || id == R.id.tv_cards) {
            StackActivity.start(getActivity());
            //搜索
        } else if (id == R.id.et_search) {
            ChatLocalSearchActivity.start(getActivity());
        } else if (id == R.id.iv_bar_add || id == R.id.iv_bar_add_1) {
            showPopWindow(ivBarAdd1);
        } else if (id == R.id.iv_bar_msg || id == R.id.iv_bar_msg_1) {
            //跳消息列表
            BCChatListActivity.start(getActivity());
        }
    }

    private void initClickIcon(View view) {
        view.findViewById(R.id.ll_scan).setOnClickListener(this);
        view.findViewById(R.id.ll_receive).setOnClickListener(this);
        view.findViewById(R.id.ll_pay).setOnClickListener(this);
        view.findViewById(R.id.ll_cards).setOnClickListener(this);
        ImageView ivScan = view.findViewById(R.id.iv_scan);
        ivScan.setOnClickListener(this);
        ImageView ivPay = view.findViewById(R.id.iv_pay);
        ivPay.setOnClickListener(this);
        ImageView ivReceive = view.findViewById(R.id.iv_receive);
        ivReceive.setOnClickListener(this);
        ImageView ivCards = view.findViewById(R.id.iv_cards);
        ivCards.setOnClickListener(this);
        TextView tvScan = view.findViewById(R.id.tv_scan);
        tvScan.setOnClickListener(this);
        TextView tvPay = view.findViewById(R.id.tv_pay);
        tvPay.setOnClickListener(this);
        TextView tvReceive = view.findViewById(R.id.tv_receive);
        tvReceive.setOnClickListener(this);
        TextView tvCards = view.findViewById(R.id.tv_cards);
        tvCards.setOnClickListener(this);
        ImageView ivBarScan = view.findViewById(R.id.iv_bar_scan);
        ivBarScan.setOnClickListener(this);
        ImageView ivBarPay = view.findViewById(R.id.iv_bar_pay);
        ivBarPay.setOnClickListener(this);
        ImageView ivBarReceive = view.findViewById(R.id.iv_bar_receive);
        ivBarReceive.setOnClickListener(this);
        ImageView ivBarCards = view.findViewById(R.id.iv_bar_cards);
        ivBarCards.setOnClickListener(this);
        ImageView ivBarAdd = view.findViewById(R.id.iv_bar_add);
        ivBarAdd.setOnClickListener(this);
        ivMsg = view.findViewById(R.id.iv_bar_msg);
        ivMsg1 = view.findViewById(R.id.iv_bar_msg_1);
        if (EnvSupportManager.isAssetHasMsg()) {
            ivMsg.setVisibility(View.VISIBLE);
            ivMsg1.setVisibility(View.VISIBLE);
            ivMsg.setOnClickListener(this);
            ivMsg1.setOnClickListener(this);
        }
        ClearEditText etSearch = view.findViewById(R.id.et_search);
        etSearch.setOnClickListener(this);
        ivBarAdd1 = view.findViewById(R.id.iv_bar_add_1);
        ivBarAdd1.setOnClickListener(this);
    }

    /**
     * 添加卡片
     */
    private void addCard() {
        // 直接读取NFC
        if (!EnvSupportManager.isSupportNfcWallet() && !EnvSupportManager.isSupportForceBleNfc()) {
            return;
        }
        // 直接读取NFC
        if (!EnvSupportManager.isSupportForceBleNfc() && Common.hasMifareClassicSupport(getActivity())) {
            MifareAddCardActivity.start(getActivity());
            //蓝牙读卡器
        } else {
            BleBlutoothScanActivity.start(getActivity(),
                    BleBlutoothScanActivity.TYPE_ADD_CARD, BleBlutoothScanActivity.BLE_TYPE_NFC);
        }
    }

    /**
     * 刷新应用菜单列表通知
     * @param eventMenuBean
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshTopMenu(EventMenuBean eventMenuBean){
        if(eventMenuBean!=null&&eventMenuBean.type == 0){
            //1、顶部加载缓存中的数据
            getMenuList();
        }
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        if(EventBus.getDefault().isRegistered(this)){
            EventBus.getDefault().unregister(this);
        }
    }

    /**
     * 刷新角标
     */
    @Subscribe(threadMode = ThreadMode.MAIN, priority = 1)
    public void onSolveMessageEvent(UpdateBadgeViewEvent event) {
        int unReadCount = BadgeUtil.getCount("wode");
        setBadge(unReadCount);
    }

    private void setBadge(int unReadCount) {
        if (EnvSupportManager.isAssetHasMsg()) {
            badgeView.setBadgeNumber(unReadCount);
            badgeView2.setBadgeNumber(unReadCount);
        }
    }

    //tabBottom里刷新界面的，用来更新角标
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshViewEvent(RefreshViewEvent event) {
        if (event.getRefreshViewID() == RefreshViewEvent.VIEW_TABOTTOMACTIVITY) {
            int unReadCount = BadgeUtil.getCount("wode");
            setBadge(unReadCount);
        }
    }

//    tabBottom里接收消息的，用来更新角标
    @Subscribe(threadMode = ThreadMode.MAIN, priority = 1, sticky = true)
    public void onSolveMessageEvent(SystemInitOverEvent event) {
        int unReadCount = BadgeUtil.getCount("wode");
        setBadge(unReadCount);
    }
}
